import js from '@eslint/js';
import createCommand from 'eslint-plugin-command/config';
import eslintComments from 'eslint-plugin-eslint-comments';
import pluginVue from 'eslint-plugin-vue';
import { defineConfig } from 'eslint/config';
import globals from 'globals';
import tseslint from 'typescript-eslint';

import { ignores } from './configs/ignores.mjs';
import { javascript } from './configs/javascript.mjs';
import { jsdoc } from './configs/jsdoc.mjs';
// import { disables } from "./configs/disableds";
import { importPluginConfig } from './configs/import.mjs';
import { perfectionistConfig } from './configs/perfectionist.mjs';

export default defineConfig([
  ...importPluginConfig(), // 导入插件配置
  ...perfectionistConfig(), // 导入插件配置
  ...(await jsdoc()), // 导入jsdoc配置
  ...(await javascript()), // 导入javascript配置
  {
    plugins: {
      'eslint-comments': eslintComments, // 提供忽略Eslint错误注释
    },
    rules: {
      'eslint-comments/no-aggregating-enable': 'error',
      'eslint-comments/no-duplicate-disable': 'error',
      'eslint-comments/no-unlimited-disable': 'error',
      'eslint-comments/no-unused-enable': 'error',
    },
  },
  {
    ...createCommand(), // 将箭头函数变成函数声明,还有promise.all一键转换;
  },
  {
    // 忽略文件
    ignores: await ignores(),
  },

  {
    extends: ['js/recommended'],
    files: ['**/*.{js,mjs,cjs,ts,mts,cts,vue}'],
    plugins: { js },
  },
  {
    files: ['**/*.{js,mjs,cjs,ts,mts,cts,vue}'],
    languageOptions: { globals: { ...globals.browser, ...globals.node } },
  },
  ...tseslint.configs.recommended,
  ...pluginVue.configs['flat/essential'],
  {
    files: ['**/*.vue'],
    languageOptions: { parserOptions: { parser: tseslint.parser } },
  },
  // 禁止使用var变量和console.log
  {
    files: ['**/*.{js,mjs,cjs,ts,mts,cts,vue}'],
    rules: {
      '@typescript-eslint/no-explicit-any': 'off',
      'no-console': 'warn', // 禁止 console.log
      'no-var': 'error', // 确保优先级最高
      'prefer-const': 'error',
    },
  },
]);
